<?php
namespace common\models;


class TradeTransfer extends BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'trade_transfer';
    }


    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['from_btype', 'to_btype'], 'required'],
            [['from_btype', 'to_btype', 'multiple', 'min_num', 'max_num', 'num_times', 'next_action', 'state', 'create_time'], 'integer'],
            [['rate'], 'number'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'from_btype' => '账本1',
            'to_btype' => '账本2',
            'multiple' => '放大倍数',
            'rate' => '手续费比例%',
            'min_num' => '最少兑换数 0为不限制',
            'max_num' => '最多兑换数 0为不限制',
            'num_times' => '多少的倍数 如100的倍数 0为不限制',
            'next_action' => '下一步触发动作 对应trade_model 的id',
            'state' => '1可操作 0禁止此操作',
            'create_time' => 'Create Time',
        ];
    }    

	/*
		* 数据列表
		* whereArr 条件
		* params 基本参数 包含 field order page limit
		* extends  扩展信息 一些相关的信息
		* 
	*/	
	public static function dataList($whereArr, $params, $extends = array())
	{
		$model  = self::find();
		$where  = isset($whereArr['where']) ? $whereArr['where'] : [];
		$whereAnd = isset($whereArr['and'])?$whereArr['and']:[];
		$models = self::queryFormart($model,$where,$params,$whereAnd);
		$model  = $models['model'];
		
		$data  = $model->asarray()->all();
		if(!$data) return array();

		//扩展信息
		if(!$extends) return $data;

		foreach($extends as $extend)
		{

		}

		return $data;	
	}

	public static function getOne($where, $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->one();
	}


	public static function getAll($where = [], $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->all();
	}

}